﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Csharp结业设计
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //全局变量部分；
        int Flag = 0 ;
        student student_infor = null;
        teacher teacher_infor = null;
        admin all = new admin();
        teacher_quary_repair_self ssr = null;
        public string username,password;

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            Flag = 1;
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            Flag = 2;
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            Flag = 3;
        }

        private void label3_Click(object sender, EventArgs e)
        {
            label3.BackColor = Color.Transparent;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            username = textBox1.Text.Trim();
            if (username == string.Empty)
            {
                MessageBox.Show("请输入用户名！");
                return;
            }

            password = textBox2.Text.Trim();
            if (password == string.Empty)
            {
                MessageBox.Show("请输入密码！");
                return;
            }

            if (Flag == 0)
            {
                MessageBox.Show("请选择登录类型！");
                return;
            }

            if (Flag == 3)
            {              
                string constr = "Data Source =LAPTOP-7I3EOIVU\\SQLEXPRESS ; Initial Catalog = Performance_management_system;" + "Integrated Security = true;";//设置连接字符串
                SqlConnection mycon = new SqlConnection(constr);  //实例化连接对象
                mycon.Open();

                SqlCommand mycom = mycon.CreateCommand();         //创建SQL命令执行对象
                string s1 = "select 用户名,密码 from Student_login where 用户名='" + username + "' and 密码='" + password + "'";//编写SQL命令

                mycom.CommandText = s1;                           //执行SQL命令
                SqlDataAdapter myDA = new SqlDataAdapter();       //实例化数据适配器
                myDA.SelectCommand = mycom;                       //让适配器执行SELECT命令
                DataSet myDS = new DataSet();                     //实例化结果数据集
                int n = myDA.Fill(myDS, "Student_login");         //将结果放入数据适配器，返回元祖个数

                if (n != 0)
                {                 
                    MessageBox.Show("欢迎使用！");               //登录成功                            
                }
                student_infor = new student(username);
                student_infor.Show();
            }
            else if (Flag == 2)
            {
                string constr = "Data Source =LAPTOP-7I3EOIVU\\SQLEXPRESS ; Initial Catalog = Performance_management_system;" + "Integrated Security = true;";//设置连接字符串
                SqlConnection mycon = new SqlConnection(constr);  //实例化连接对象
                mycon.Open();

                SqlCommand mycom = mycon.CreateCommand();         //创建SQL命令执行对象
                string s1 = "select 用户名,密码 from Teacher_login where 用户名='" + username + "' and 密码='" + password + "'";//编写SQL命令

                mycom.CommandText = s1;                           //执行SQL命令
                SqlDataAdapter myDA = new SqlDataAdapter();       //实例化数据适配器
                myDA.SelectCommand = mycom;                       //让适配器执行SELECT命令
                DataSet myDS = new DataSet();                     //实例化结果数据集
                int n = myDA.Fill(myDS, "Teacher_login");         //将结果放入数据适配器，返回元祖个数

                if (n != 0)
                {
                    MessageBox.Show("欢迎使用！");               //登录成功                            
                }
                ssr = new teacher_quary_repair_self(username);
                teacher_infor = new teacher(username);
                teacher_infor.Show();
            }
            else if (Flag == 1)
            {
                string constr = "Data Source =LAPTOP-7I3EOIVU\\SQLEXPRESS ; Initial Catalog = Performance_management_system;" + "Integrated Security = true;";//设置连接字符串
                SqlConnection mycon = new SqlConnection(constr);  //实例化连接对象
                mycon.Open();

                SqlCommand mycom = mycon.CreateCommand();         //创建SQL命令执行对象
                string s1 = "select 用户名,密码 from Admin_login where 用户名='" + username + "' and 密码='" + password + "'";//编写SQL命令

                mycom.CommandText = s1;                           //执行SQL命令
                SqlDataAdapter myDA = new SqlDataAdapter();       //实例化数据适配器
                myDA.SelectCommand = mycom;                       //让适配器执行SELECT命令
                DataSet myDS = new DataSet();                     //实例化结果数据集
                int n = myDA.Fill(myDS, "Admin_login");         //将结果放入数据适配器，返回元祖个数
                if (n != 0)
                {
                    MessageBox.Show("欢迎使用！");               //登录成功                            
                }
                all.Show();
            }
        }
    }
}
